const state = {
  data: [],
  page: {}
}

const actions = {
  saveData: ({ commit }, payload) => {
    commit('SAVEDATA', payload)
  }
}

const mutations = {
  SAVEDATA: (state, payload) => {
    if (payload.result.length === 0) {
      state.data = []
    } else {
      state.data = payload.result.map(item => {
        return {
          ...item,
          publicAt: item.public_at
        }
      })
    }
    state.page = {
      size: 10,
      total: payload.resultNum,
      number: payload.number || 1
    }
  }
}

export default {
  state,
  actions,
  mutations
}